﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admincp/Admin.Master" AutoEventWireup="true"
    CodeBehind="Hang.aspx.cs" Inherits="TPCN.Admincp.Hang" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="name" ContentPlaceHolderID="nameholder" runat="server">Sản phẩm</asp:Content>
<asp:Content ID="maincontent" ContentPlaceHolderID="maincontent" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <asp:Panel ID="ButtonPanel" runat="server" CssClass="right">
        <asp:Button ID="btnInsert" runat="server" Text="Thêm sản phẩm" CssClass="button button-green"
            OnClick="btnInsert_Click" />
        <asp:Button ID="btnDelete" runat="server" Text="Xóa" CssClass="button button-green"
            OnClick="btnDelete_Click" OnClientClick="return confirm('Bạn có muốn xóa những sản phẩm đã chọn không?');" />
    </asp:Panel>
    <asp:Panel ID="ErrorPanel" runat="server">
        <asp:ValidationSummary ID="summary" runat="server" CssClass="message error" />
    </asp:Panel>
    <hr />
    <asp:Panel ID="GridViewPanel" runat="server">
        <asp:GridView ID="HangGridView" runat="server" AutoGenerateColumns="False" Width="100%"
            DataKeyNames="HangID" Height="16px" OnRowCommand="HangGridView_RowCommand" AllowPaging="True"
            GridLines="None" CssClass="mGrid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"
            OnPageIndexChanging="HangGridView_PageIndexChanging" PageSize="15">
            <AlternatingRowStyle CssClass="alt" />
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSelect" runat="server" CssClass="chkItem" />
                    </ItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkSelectAll" runat="server" CssClass="chkHeader" />
                    </HeaderTemplate>
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                </asp:TemplateField>
                <asp:BoundField DataField="HangID" HeaderText="HangID" ReadOnly="True">
                    <HeaderStyle CssClass="hide" />
                    <ItemStyle CssClass="hide" />
                </asp:BoundField>
                <asp:ImageField DataAlternateTextField="Tenhang" DataImageUrlField="Anh" HeaderText="Ảnh minh họa">
                    <ControlStyle Height="50px" Width="50px" />
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </asp:ImageField>
                <asp:BoundField DataField="Tenhang" HeaderText="Tên sản phẩm" />
                <asp:BoundField DataField="Solanmua" HeaderText="Số lần được mua" >
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="Thutu" HeaderText="Thứ tự" >
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:CheckBoxField DataField="Active" HeaderText="Hiển thị" >
                <ItemStyle HorizontalAlign="Center" />
                </asp:CheckBoxField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="btn_CMD_Edit" runat="server" CommandArgument='<%# Eval("HangID") %>'
                            CommandName="cmdEdit">Sửa</asp:LinkButton>
                        <asp:LinkButton ID="btn_CMD_Delete" runat="server" CommandArgument='<%# Eval("HangID") %>'
                            CommandName="cmdDelete" OnClientClick="return confirm('Bạn có muốn xóa sản phẩm này không?');">Xóa</asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                </asp:TemplateField>
            </Columns>
            <HeaderStyle HorizontalAlign="Left" />
            <PagerSettings FirstPageText="Đầu" LastPageText="Cuối" Mode="NumericFirstLast" NextPageText="Tiếp"
                PreviousPageText="Trước" PageButtonCount="5" />
            <PagerStyle CssClass="pgr" />
        </asp:GridView>
    </asp:Panel>
    <asp:Panel ID="EditFormPanel" runat="server">
        <table id="editForm">
            <tbody>
                <tr>
                    <td class="label">
                        Tên sản phẩm
                    </td>
                    <td>
                        <asp:TextBox ID="txtTenhang" runat="server" Width="230px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="requiredTenhang" runat="server" ControlToValidate="txtTenhang"
                            ErrorMessage="Tên sản phẩm không được để trống">*</asp:RequiredFieldValidator>
                    </td>
                    <td class="label">
                        Tiêu đề
                    </td>
                    <td>
                        <asp:TextBox ID="txtTitle" runat="server" Width="230px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        Xuất xứ
                    </td>
                    <td>
                        <asp:TextBox ID="txtXuatxu" runat="server" Width="230px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="requiredXuatxu" runat="server" ControlToValidate="txtXuatxu"
                            ErrorMessage="Xuất xứ sản phẩm không được để trống">*</asp:RequiredFieldValidator>
                    </td>
                    <td class="label">
                        Từ khóa
                    </td>
                    <td>
                        <asp:TextBox ID="txtKeyword" runat="server" Width="230px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        Thứ tự
                    </td>
                    <td>
                        <asp:TextBox ID="txtThutu" runat="server" Width="230px"></asp:TextBox>
                        <asp:CompareValidator ID="compareThutu" runat="server" ControlToValidate="txtThutu"
                            ErrorMessage="Thứ tự phải là số và nguyên dương" Operator="GreaterThanEqual"
                            Type="Integer" ValueToCompare="0">*</asp:CompareValidator>
                    </td>
                    <td class="label">
                        Mô tả tìm kiếm
                    </td>
                    <td>
                        <asp:TextBox ID="txtDescription" runat="server" Width="230px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        Giá bán lẻ
                    </td>
                    <td>
                        <telerik:RadNumericTextBox ID="txtGiabanle" runat="server" Width="230px" EnableEmbeddedSkins="False"
                            EnableTheming="False" MinValue="0" Value="0" EnableEmbeddedBaseStylesheet="False">
                            <NumberFormat DecimalDigits="0" />
                            <EnabledStyle PaddingBottom="4px" PaddingLeft="6px" PaddingRight="6px" PaddingTop="4px" />
                        </telerik:RadNumericTextBox>
                    </td>
                    <td class="label">
                        Giá thị trường
                    </td>
                    <td>
                        <telerik:RadNumericTextBox ID="txtGiathitruong" runat="server" Width="230px" EnableEmbeddedSkins="False"
                            EnableTheming="False" MinValue="0" Value="0">
                            <NumberFormat DecimalDigits="0" />
                            <EnabledStyle PaddingBottom="4px" PaddingLeft="6px" PaddingRight="6px" PaddingTop="4px" />
                        </telerik:RadNumericTextBox>
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        Giá bán buôn
                    </td>
                    <td>
                        <telerik:RadNumericTextBox ID="txtGiabanbuon" runat="server" Width="230px" EnableEmbeddedSkins="False"
                            EnableTheming="False" MinValue="0" Value="0">
                            <NumberFormat DecimalDigits="0" />
                            <EnabledStyle PaddingBottom="4px" PaddingLeft="6px" PaddingRight="6px" PaddingTop="4px" />
                        </telerik:RadNumericTextBox>
                    </td>
                    <td class="label">
                        Hiển thị
                    </td>
                    <td>
                        <asp:CheckBox ID="chkActive" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        Đơn vị tính
                    </td>
                    <td colspan="3">
                        <asp:DropDownList ID="cboDonvitinh" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="label top">
                        Chọn danh mục
                    </td>
                    <td colspan="3">
                        <telerik:RadListBox ID="listCategory" runat="server" CheckBoxes="True" DataKeyField="DanhmucID"
                            DataTextField="Tendanhmuc" DataValueField="DanhmucID" SelectionMode="Multiple" Width="600px">
                        </telerik:RadListBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div class="message info top">
                            <div id="ImagePanel" runat="server">
                                <table>
                                    <tr>
                                        <td rowspan="3">
                                            <asp:Image ID="imgAnh" runat="server" Height="120px" Width="120px" />
                                        </td>
                                        <td class="h40">
                                            <select id="cboType" onchange="oncboTypeChange()" runat="server">
                                                <option value="0">Ảnh trên mạng</option>
                                                <option value="1">Ảnh trên máy chủ</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="h40">
                                            <div id="txtAnhContainer">
                                                <telerik:RadTextBox ID="txtAnh" runat="server" EnableEmbeddedBaseStylesheet="False"
                                                    EnableEmbeddedSkins="False" EnableTheming="False" Width="300px">
                                                </telerik:RadTextBox>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="h40">
                                            <div id="upload" style="display: none">
                                                <asp:Button ID="btnBrowse" runat="server" CssClass="button button-gray" Text="Browse server"
                                                    UseSubmitBehavior="False" CausesValidation="False" OnClientClick="OpenFileExplorerDialog(); return false;" />
                                                <script type="text/javascript">

                                                    function OpenFileExplorerDialog() {
                                                        var wnd = $find("<%= serverExplorer.ClientID %>");
                                                        wnd.show();
                                                    }

                                                    function OnFileSelected(fileSelected) {
                                                        var txtUrl = $find("<%= txtAnh.ClientID %>");
                                                        txtUrl.set_value("~" + fileSelected);
                                                    }

                                                    function openUploader() {
                                                        var imagePanel = document.getElementById("<%= ImagePanel.ClientID %>");
                                                        var uploadPanel = document.getElementById("UploadPanel");
                                                        imagePanel.style.display = 'none';
                                                        uploadPanel.style.display = 'block';
                                                    }

                                                    function onUploadSubmit() {
                                                        var imagePanel = document.getElementById("<%= ImagePanel.ClientID %>");
                                                        var uploadPanel = document.getElementById("UploadPanel");
                                                        uploadPanel.style.display = 'none';
                                                        imagePanel.style.display = 'block';
                                                    }

                                                    function oncboTypeChange() {
                                                        var panelupload = document.getElementById("upload");
                                                        var cboType = document.getElementById("<%= cboType.ClientID %>");
                                                        if (cboType.selectedIndex == 0)
                                                            panelupload.style.display = 'none';
                                                        else
                                                            panelupload.style.display = 'block';
                                                    }
                                                </script>
                                                <asp:Button ID="btnUpload" runat="server" CssClass="button button-gray" Text="Upload"
                                                    UseSubmitBehavior="False" CausesValidation="False" OnClientClick="openUploader(); return false;" />
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <telerik:RadAjaxManager ID="ajaxManager" runat="server">
                                <AjaxSettings>
                                    <telerik:AjaxSetting AjaxControlID="btnSubmitUpload">
                                        <UpdatedControls>
                                            <telerik:AjaxUpdatedControl ControlID="ImagePanel" LoadingPanelID="loadingPanel" />
                                        </UpdatedControls>
                                    </telerik:AjaxSetting>
                                </AjaxSettings>
                            </telerik:RadAjaxManager>
                            <telerik:RadAjaxLoadingPanel ID="loadingPanel" runat="server" />
                            <div id="UploadPanel" style="display: none">
                                <telerik:RadProgressManager ID="processManager" runat="server" />
                                <telerik:RadAsyncUpload ID="uploader" runat="server" InputSize="50" MaxFileInputsCount="1" 
                                    TargetFolder="~/Upload" Width="380px" TemporaryFolder="~/Admincp/RadUploadTemp">
                                </telerik:RadAsyncUpload>
                                <telerik:RadProgressArea ID="processArea" runat="server" />
                                <asp:Button ID="btnSubmitUpload" OnClientClick="onUploadSubmit();" runat="server"
                                    CssClass="button button-gray buttontop" Text="Upload" OnClick="btnSubmitUpload_Click"
                                    CausesValidation="False" UseSubmitBehavior="False" />
                                <asp:Button ID="btnCancelUpload" OnClientClick="onUploadSubmit(); return false;" runat="server"
                                    CssClass="button button-gray buttontop" Text="Cancel" 
                                    CausesValidation="False" EnableViewState="False" ViewStateMode="Disabled" />
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        Thông tin sơ lược
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtThongtinsoluoc"
                            ErrorMessage=" Thông tin của sản phẩm không được để trống">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <asp:TextBox ID="txtThongtinsoluoc" runat="server" Height="100px" TextMode="MultiLine"
                            Width="98%" TabIndex="9" />
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        Thông tin chi tiết
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtThongtinchitiet"
                            ErrorMessage="Thông tin sản phẩm không được để trống" ValidationGroup="required">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <telerik:RadEditor ID="txtThongtinchitiet" runat="server" Height="500px" Width="100%"
                            EditModes="Design" NewLineBr="False" NewLineMode="Div" TabIndex="10" 
                            ToolsFile="~/Admincp/toolbar.xml">
                            <Content ></Content>
                        </telerik:RadEditor>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" class="center">
                        <asp:Button ID="btnSave" runat="server" Text="Cập nhật" CssClass="button button-green groupbutton"
                            OnClick="btnSave_Click" />
                        <asp:Button ID="btnCancel" runat="server" Text="Hủy bỏ" CssClass="button button-green groupbutton"
                            OnClick="btnCancel_Click" TabIndex="12" CausesValidation="False" 
                            UseSubmitBehavior="False" EnableViewState="False" />
                    </td>
                </tr>
            </tbody>
        </table>
    </asp:Panel>
    <div class="clear">
    </div>
    <telerik:RadWindow ID="serverExplorer" runat="server" Behaviors="Close, Move" Height="560px"
        Modal="True" NavigateUrl="Explorer.aspx" ShowContentDuringLoad="False" VisibleStatusbar="False"
        Width="550px">
    </telerik:RadWindow>
</asp:Content>
